package vn.co.thn.android.videohot.activity;

import java.util.List;

import vn.co.thn.android.videohot.R;
import vn.co.thn.android.videohot.VHConstants;
import vn.co.thn.android.videohot.common.VHCommonActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class VHChooseVideoActivity extends VHCommonActivity {
	private static final String LOG_TAG = VHChooseVideoActivity.class.getSimpleName();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit);
		setContentView(R.layout.vh_choose_activity);
		findViewById(R.id.gallery).setOnClickListener(this);
		findViewById(R.id.movie).setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		
		case R.id.gallery:
			Intent intent = new Intent();
			intent.setAction(Intent.ACTION_PICK);
			intent.setType("video/*");

			List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
			if (list.size() <= 0) {
				Log.d(LOG_TAG, "no video picker intent on this hardware");
				return;
			}

			startActivityForResult(intent, VHConstants.REQUEST_CODE_GALLERY);
			break;
		case R.id.movie:
			Intent i = new Intent();
			i.setAction("android.media.action.VIDEO_CAPTURE");
			startActivityForResult(i, VHConstants.REQUEST_CODE_CAMERA);
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case VHConstants.REQUEST_CODE_CAMERA:
		case VHConstants.REQUEST_CODE_GALLERY:
			if (resultCode == RESULT_OK) {
				Intent upload = new Intent(getApplicationContext(), VHUpLoadVideoActivity.class);
				upload.setData(data.getData());
				startActivityForResult(upload, VHConstants.REQUEST_CODE_UPLOAD);
			}
			break;
		}
	}
}
